<template>
    <div class="page-100 login-register-part">
        <yd-cell-item style="padding-bottom: 20px">
            <img  slot="left" class="login-img" src="../../assets/loginxingming.png">
            <input slot="right" type="text" placeholder="姓名" v-model="name" maxlength="20">
        </yd-cell-item >
        <yd-cell-item style="padding-bottom: 20px">
            <img  slot="left" class="login-img" src="../../assets/loginsouzaidi.png">
            <span  slot="right" style="text-align: left;position: absolute;left: 0.8rem;font-size: 0.3rem" >{{address}}</span>
        </yd-cell-item>
        <yd-cell-item style="padding-bottom: 20px">
            <img  slot="left" class="login-img" src="../../assets/logindanwei.png">
            <span  slot="right" style="text-align: left;position: absolute;left: 0.8rem;font-size: 0.3rem" >{{bankName}}</span>
        </yd-cell-item>
        <yd-cell-item style="padding-bottom: 20px">
            <img  slot="left" class="login-img" src="../../assets/loginjigou.png">
            <span  slot="right" style="text-align: left;position: absolute;left: 0.8rem;font-size: 0.3rem" >{{inst}}</span>
        </yd-cell-item>

        <yd-button  size="large" type="primary" @click.native="handleClick" style="background-color:#3cc8a8;color:white;height: 40px">确认</yd-button>

    </div>
</template>

<script>
    import {activated3} from "../../pcof/post";
    import {openId,userInfoData,registryFlag} from '../../globalVariables'
    import WeuiDistpicker from 'weui-distpicker';
    export default {
        name: "loginActive",
        data() {
            // var obj = JSON.stringify(city);

            return {
                name: '',
                bankName:'',//单位
                address:'',
                inst:'',//机构
            }
        },
        component: {
            WeuiDistpicker,
        },
        mounted() {
            let that = this;

            var geolocation = new BMap.Geolocation();
            // 创建地理编码实例
            var myGeo = new BMap.Geocoder();
            geolocation.getCurrentPosition(function(r){
                if(this.getStatus() == BMAP_STATUS_SUCCESS){
                    var pt = r.point;
                    // 根据坐标得到地址描述
                    myGeo.getLocation(pt, function(result){
                        if (result){
                            var addComp = result.addressComponents;
                            that.province=addComp.province;
                            that.city=addComp.city;
                            that.district=addComp.district;
                            console.log(addComp);
                            console.log(that.district + "," + that.district+'，'+that.district);
                            that.address = that.province + that.city + that.district;
                        }
                    });
                }
            });
        },
        created() {
            this.isregistry = this.$route.params.isregistry;
            console.log('数据'+this.isregistry);
            console.log(localStorage.getItem(userInfoData));
            this.name = JSON.parse(localStorage.getItem(userInfoData)).name;

            this.bankName=JSON.parse(localStorage.getItem(userInfoData)).partnerName;
            this.address = JSON.parse(localStorage.getItem(userInfoData)).province+JSON.parse(localStorage.getItem(userInfoData)).city+JSON.parse(localStorage.getItem(userInfoData)).district;
            this.inst = JSON.parse(localStorage.getItem(userInfoData)).bankName;
        },
        methods: {
            /**异步请求函数 加上async 注册请求 */
            async handleClick() {
                if (this.name === ''||this.name.length<2||this.name.length>5) {
                    this.$dialog.toast({
                        mes: "请输入真实姓名!",
                        timeout: 1500
                    });
                    return;
                }
                //    name: name,

                var response = await activated3(JSON.parse(localStorage.getItem(userInfoData)).mobile,this.name);
                if (response.data.code === 200) {
                    //用户状态：0-正常，1-审批中，3-被拒绝 登录之后
                    var state=response.data.customer.state;
                    if (state === '0') {
                        this.$router.push({name: 'homeDetail', params: {mobile: JSON.parse(localStorage.getItem(userInfoData)).mobile}});
                    }else if (state === '1'|| state === '3') {
                        this.$router.push({name: 'loginCheckinfo',params: {loginUserState: response.data.data.state}});
                    }
                }else
                {
                    this.$dialog.toast({
                        mes: response.data.msg,
                        timeout: 1500
                    });
                }


            },

            /** 异步请求函数 加上async */
            handleAddressClick() {
                this.isShowAddresPick = true;
            },
            /** 确定所在地Picker回调监听 */
            onAddresConfirm(data) {
                this.isShowAddresPick = false;
                this.province = data[0].label;
                this.city = data.length >= 2 ? data[1].label : '';
                this.district = data.length == 3 ? data[2].label : '';
                this.address = this.province + this.city + this.district;

            },
            /** 取消所在地Picker回调监听 */
            onAddresCancel() {
                this.isShowAddresPick = false;
            },
            /** 显示所在单位事件 */
            async handleShowPlace() {
                var response = await getAllPartnerInfos();
                if (response.data.code === 200) {
                    let that = this;
                    var arr = response.data.data;
                    if(arr.length>0)
                    {
                        var newAr = new Array();
                        for (var i = 0; i < arr.length; i++) {
                            var item = response.data.data[i];
                            newAr.push({'label': item.name, 'value': item.uuid});
                        }
                        weui.picker(
                            newAr,
                            {
                                onChange(result) {
                                    console.log(result);

                                },
                                onConfirm(result) {

                                    that.place = result[0].label;
                                    that.bankUuid = result[0].value;
                                },
                            },
                        );
                    }else
                    {
                        if (this.address === '') {
                            this.$dialog.toast({
                                mes: "当前没有机构!",
                                timeout: 1500
                            });
                            return;
                        }

                    }

                }
            },
            //选择所属机构
            //000000000011 杭州银行总行
            //目前只有杭州银行总行 有数据
            async handleInstClick() {
                if (this.address === '') {
                    this.$dialog.toast({
                        mes: "请先选择所在地!",
                        timeout: 1500
                    });
                    return;
                }
                if (this.place === '') {
                    this.$dialog.toast({
                        mes: "请先选择所在单位!",
                        timeout: 1500
                    });
                    return;

                }

                var response = await getInstInfos(this.bankUuid, this.province,this.city, this.district);
                if (response.data.code === 200) {
                    let that = this;
                    var arr = response.data.data;
                    if(arr.length>0)
                    {
                        var newAr = new Array();
                        for (var i = 0; i < arr.length; i++) {
                            var item = response.data.data[i];
                            newAr.push({'label': item.name, 'value': item.uuid});
                        }
                        weui.picker(
                            newAr,
                            {
                                onChange(result) {

                                },
                                onConfirm(result) {

                                    that.inst = result[0].label;
                                    that.inst_uuid = result[0].value;

                                },
                            },
                        );

                    }else
                    {
                        this.$dialog.toast({
                            mes: '当前没有机构!',
                            timeout: 1500
                        });
                        return;
                    }

                }else {
                    this.$dialog.toast({
                        mes: response.data.msg,
                        timeout: 1500
                    });
                }
            },

        }

    }
</script>

<style lang="scss">
    @import "../login/login.scss";
</style>